<!DOCTYPE html>
<html lang="zh-CN" xmlns:th="http://www.thymeleaf.org">
<head>
    <div th:replace="./widget/base"></div>
</head>
<body>

<!--<div class="easyui-layout" data-options="fit:true">-->
    <!--<div data-options="region:'west',split:true" style="width:40%">-->
        <!--<div id="moveDialogDictionaryCategoryToolbar">-->
            <!--<a th:if="${#authorization.expression('hasRole('''+ SYSTEM_ADMIN +''') OR hasAuthority(''/COMPONENT/SYSTEM/DICTIONARY/PAGE_ALL/DICTIONARY_CATEGORY_ADD_DIALOG'')')}"-->
               <!--href="javascript:" class="easyui-linkbutton" iconCls="fa fa-plus" plain="true"-->
               <!--onclick="dictionaryCategoryAddDialog();">新增</a>-->

            <!--<a th:if="${#authorization.expression('hasRole('''+ SYSTEM_ADMIN +''') OR hasAuthority(''/COMPONENT/SYSTEM/DICTIONARY/PAGE_ALL/DICTIONARY_CATEGORY_EDIT_DIALOG'')')}"-->
               <!--href="javascript:" class="easyui-linkbutton" iconCls="fa fa-edit" plain="true"-->
               <!--onclick="dictionaryCategoryEditDialog();">编辑</a>-->

            <!--<a th:if="${#authorization.expression('hasRole('''+ SYSTEM_ADMIN +''') OR hasAuthority(''/COMPONENT/SYSTEM/DICTIONARY/PAGE_ALL/DICTIONARY_CATEGORY_DELETE_ALL'')')}"-->
               <!--href="javascript:" class="easyui-linkbutton" iconCls="fa fa-close" plain="true"-->
               <!--onclick="dictionaryCategoryDeleteAll();">删除</a>-->

        <!--</div>-->
        <table id="moveToDictionaryCategoryDialog"></table>
    <!--</div>-->
<!--</div>-->

<script type="text/javascript">
    $(function () {
        var columns = [
            {field: 'checkbox', checkbox: true},
            {field: 'id', title: 'ID'},
            {field: 'name', title: '分类名称'},
            {field: 'sort', title: '排序'},
            {field: 'remark', title: '备注'},
            {field: 'gmtModified', title: '更新时间'},
            {field: 'gmtCreated', title: '创建时间'}
        ];
        $('#moveToDictionaryCategoryDialog').treegrid(expressui.grid.create, {
            url: Url.System.Api.DICTIONARY_CATEGORY + '/page_all_parent',
            expandUrl: Url.System.Api.DICTIONARY_CATEGORY + '/list_all_by_parent_id/{id}',
            columns: [columns],
        });
    });

    function dictionaryCategoryAddDialog() {
        var one = $('#dictionaryCategory').treegrid(expressui.grid.getCheckedOneNoCheckedOrShowAlert);
        if (!one) {
            return;
        }

        $('#dictionaryCategoryAddDialog').dialog(expressui.dialog.create, {
            title: '新增字典分类',
            grid: {type: 'treegrid', selector: '#dictionaryCategory'},
            href: Url.System.Page.DICTIONARY_CATEGORY + '/add_dialog',
            save: {
                url: Url.System.Api.DICTIONARY_CATEGORY + '/add_one',
                data: one ? {parentId: one.id} : {},
                method: 'post'
            },
            buttons: [{
                text: '保存',
                iconCls: 'fa fa-save',
                handler: expressui.dialog.add,
                reload: [{type: 'treegrid', selector: '#dictionaryCategory'}, {
                    type: 'datagrid',
                    selector: '#dictionary',
                    data: []
                }],
                success: '新增成功'
            }, {
                text: '关闭',
                iconCls: 'fa fa-close',
                handler: expressui.dialog.close
            }]
        });
    }

    function dictionaryCategoryEditDialog() {
        var one = $('#dictionaryCategory').treegrid(expressui.grid.getCheckedOneOrShowAlert);
        if (!one) {
            return;
        }

        $('#dictionaryCategoryEditDialog').dialog(expressui.dialog.create, {
            title: '编辑字典分类',
            grid: {type: 'treegrid', selector: '#dictionaryCategory'},
            href: Url.System.Page.DICTIONARY_CATEGORY + '/edit_dialog',
            get: {url: Url.System.Api.DICTIONARY_CATEGORY + '/one/{id}', method: 'get'},
            save: {url: Url.System.Api.DICTIONARY_CATEGORY + '/save_one', method: 'post'},
            buttons: [{
                text: '保存',
                iconCls: 'fa fa-save',
                handler: expressui.dialog.save,
                reload: [{type: 'treegrid', selector: '#dictionaryCategory'}, {
                    type: 'datagrid',
                    selector: '#dictionary',
                    data: []
                }],
                success: '保存成功'
            }, {
                text: '关闭',
                iconCls: 'fa fa-close',
                handler: expressui.dialog.close
            }]
        });
    }

    function dictionaryCategoryDeleteAll() {
        $('#dictionaryCategory').treegrid(expressui.grid.postCheckedLessOneOrShowAlert, {
            url: Url.System.Api.DICTIONARY_CATEGORY + '/delete_all',
            method: 'post',
            success: '删除成功',
            reload: [{type: 'treegrid', selector: '#dictionaryCategory'}, {
                type: 'datagrid',
                selector: '#dictionary',
                data: []
            }]
        });
    }

    function dictionaryCategoryExportAll() {
        var checked = $('#dictionaryCategory').treegrid('getChecked');
        var id = [];
        if(checked && checked.length>0) {
            for (var i = 0; i < checked.length; i++) {
                id.push(checked[i].id);
            }
            window.open(Url.System.Api.DICTIONARY + '/export_all_by_dictionary_category_id_list?id=' + id)
        }
    }

</script>
</body>
</html>